package com.whsxt.controller;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 贺炯
 * @since 2019-09-18
 */
@Controller
@RequestMapping("/sys/user")
public class UserController {
	
	@RequestMapping("/tologin")
	public String toLogin() {
		return "login";
	}
	
	@RequestMapping("/login")
	public String list(String username,String password) {
		Subject subject = SecurityUtils.getSubject();
		AuthenticationToken token = new UsernamePasswordToken(username, password);
		try {
			subject.login(token);
			return "redirect:/sys/user/list";
		} catch (AuthenticationException e) {
			e.printStackTrace();
			return "redirect:/index.html";
		}
	}
	@RequestMapping("/list")
	public String toList() {
		return "list";
	}
	
}

